package com.zq.kkdady.redis.controller;


import com.zq.kkdady.redis.pojo.User;
import com.zq.kkdady.redis.sercive.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ピカチュウ(皮卡啾)
 * @date 2021/7/21 14:05
 * @Description:
 */

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/all")
    public List queryAll() {
        List list = userService.queryAll();
        return list;
    }


    @RequestMapping("/bid/{id}")
    public User bid(@PathVariable("id") int id) {
        return userService.findUserById(id);
    }


    @RequestMapping("/up/{id}")
    public String updateUser(@PathVariable("id") int id) {
        User user = new User();
        user.setId(String.valueOf(id));
        user.setName("cat");
        user.setPwd("miaomiao");

        int result = userService.updateUser(user);

        if (result != 0) {
            return "update user success";
        } else
            return "fail";
    }

    @RequestMapping("/del/{id}")
    public String deleteUserById(@PathVariable("id") int id) {
        int result = userService.deleteUserById(id);
        if (result != 0) {
            return "delete success";
        } else
            return "delete fail";
    }


}
